import { _decorator, Component, tween, v3 } from 'cc';
const { ccclass, property,menu } = _decorator;

@ccclass('ComBreatheAction')
@menu("扩展组件/ComBreatheAction")
export class ComBreatheAction extends Component {
    @property({tooltip:"运动时间"})
    duration: number = 1.0;

    @property({tooltip:"下一次间隔时间"})
    delayTime: number = 3.0;

    @property({tooltip:"变到正常后到开始运动间隔时间"})
    spanTime: number = 1.0;

    private tween: any;
    protected onLoad(): void {
        this.node.setScale(0,0,0);
    }
    start() {

    }

    update(deltaTime: number) {

    }

    onEnable() {
        this.tween = tween(this.node).repeatForever(tween(this.node)
            .call(()=>{
                this.node.setScale(0,0,0);
            })
            .to(0.5 / this.duration, { scale: v3(1,1,1) })
            .delay(this.spanTime)
            .to(0.5 / this.duration, { scale: v3(1.08,1.08,1) })
            .to(0.5 / this.duration, { scale: v3(0.98,0.98,1) })
            .to(0.5 / this.duration, { scale: v3(1.08,1.08,1) })
            .to(0.5 / this.duration, { scale: v3(0.98,0.98,1) })
            .to(0.5 / this.duration, { scale: v3(1.08,1.08,1) })
            .to(0.5 / this.duration, { scale: v3(0.98,0.98,1) })
            .delay(this.spanTime)
            .to(0.5 / this.duration, { scale: v3(0,0,0) })
            .delay(this.delayTime)
        ).start();;
    }

    onDisable() {
        if (this.tween) {
            this.tween.stop();
            this.tween = null;
        }
    }
}

